import { GET_ROLE_USER_LIST_API } from "@/api";
import http from "@/utils/http";
import { Table, message } from "antd";
import React, { useState, useEffect } from "react";

/**
 * @description 成员列表
 */

const AuthorityUserList = ({ selected }) => {
    const [loading, setLoading] = useState(false);
    const [state, setState] = useState({
        total: 0,
        list: []
    })
    const [params, setParams] = useState({
        roleId: null,
        roleName: null
    })

    const columns = [
        {
            title: "用户名",
            key: "userId",
            dataIndex: "userId"
        },
        {
            title: "姓名",
            key: "userName",
            dataIndex: "userName"
        },

    ]


    //get roleList

    const getUserList = () => {
        http.post({
            url: GET_ROLE_USER_LIST_API,
            params: {
                ...params
            },
            before: () => setLoading(true),
            success: res => {
                setState({
                    total: res.data.total || 0,
                    list: res.data.list || []
                })
            },
            failure: msg => {
                message.error(msg)
            },
            complete: () => setLoading(false),
        })
    }

    useEffect(() => {
        getUserList()
    }, [params])

    useEffect(() => {
        setParams({
            ...params,
            roleId: selected._id,
            roleName: selected.roleName
        })
    }, [selected])
    return (
        <>
            <Table loading={loading} dataSource={state.list} columns={columns} />
        </>
    )
}
export default AuthorityUserList;